﻿using BenchmarkDotNet.Attributes;
using ExpressionBuilder.Common;
using ExpressionBuilder.Generics;
using ExpressionBuilder.Operations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BenchMarkTest.ExpressionBuilderTest
{
    [RankColumn]
    public class Fifter_In
    {
        private readonly List<User> _haystack = new List<User>();
        private readonly int _haystackSize = 100000;
        private static readonly string _name1 = "jack";
        private static readonly string _name2 = "need";
        private static readonly string _name3 = "tony";
        private static readonly string name = "Name";
        private readonly List<string> names = new List<string>() { _name1, _name3 };
        public Fifter_In()
        {
            Enumerable.Range(1, _haystackSize).ToList().ForEach(x => _haystack.Add(new User()
            {
                Id = x,
                Name = x / 2 == 0 ? _name1 : (x / 3 == 0 ? _name2 : _name3)
            }));
        }


        /// <summary>
        /// 
        /// </summary>
        [Benchmark]
        public void QueryFifter()
        {
            var queryable = _haystack.AsQueryable();
            var filter = new Filter<User>();
            filter.By(name, Operation.In, names);
            queryable.Where(filter).ToList();
        }

        /// <summary>
        /// 
        /// </summary>
        [Benchmark]
        public void QueryLinq()
        {
            var queryable = _haystack.AsQueryable();
            queryable.Where(x => names.Contains(x.Name)).ToList();
        }
    }
}
